package com.fbinggun.sql;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Util {
    //获取当前时间
    public static Long date() {
        Calendar cal = Calendar.getInstance();
        Date date = cal.getTime();

        return date.getTime();

    }
    //将时间转换为时间戳
    public static Long dateToStamp(String s) throws Exception {
        //设置时间格式，将该时间格式的时间转换为时间戳
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = simpleDateFormat.parse(s);
        long time = date.getTime();

        return time;
    }

    //将时间戳转换为时间
    public static String stampToTime(long lt) throws Exception{
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        //将时间戳转换为时间
        Date date = new Date(lt*1000);
        //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
        res = simpleDateFormat.format(date);
        return res;
    }
    public static String stampToTime(long lt,boolean t) throws Exception{
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        //将时间戳转换为时间
        Date date = new Date(lt);
        //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
        res = simpleDateFormat.format(date);
        return res;
    }


    //判断时效
    public static boolean ISTimeLimit(Long pd,Long dq,boolean t) throws ParseException {


                  boolean b =pd >= dq;
                  if(t){
                      return b;
                  }else {
                      return !b;
                  }

    }


    public static Long getDateTiemString(String s) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        if(s.contains("月")){
            simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        }else  if(s.contains("-")){
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        }else  if(s.contains("/")){
            simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");

        }else  if(s.contains(".")){
            simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd");
        }
        Date date = simpleDateFormat.parse(s);
        long time = date.getTime();
        return time;
    }






}
